package com.ck.ips.service.impl.program;

import com.ck.common.model.ProgramDevice;
import com.ck.ips.dao.program.ProgramDeviceMapper;
import com.ck.ips.model.vo.program.ProgramDeviceBasicInfoVO;
import com.ck.ips.model.vo.program.ProgramStatisticsInfoVO;
import com.ck.ips.service.program.ProgramDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author linqiang
 * @version v1.0
 * @Description
 * @date 2019-04-29 16:41
 */
@Service(value = "programDeviceService")
public class ProgramDeviceServiceImpl implements ProgramDeviceService {

    @Autowired
    private ProgramDeviceMapper programDeviceMapper;

    /**
     * 批量新增
     *
     * @param programDeviceList
     * @return
     */
    @Override
    public int batchInsert(List<ProgramDevice> programDeviceList) {
        return programDeviceMapper.batchInsert(programDeviceList);
    }

    /**
     * 根据节目版本号查询设备基础信息
     *
     * @param programVersion 节目版本号
     * @return List
     */
    @Override
    public List<ProgramDeviceBasicInfoVO> listDeviceBasicInfoByProgramVersion(String programVersion) {
        return programDeviceMapper.listDeviceBasicInfoByProgramVersion(programVersion);
    }

    /**
     * 根据节目版本号统计终端数量和终端组数量
     *
     * @param programVersion 节目版本号
     * @return ProgramInfoCountVO
     */
    @Override
    public ProgramStatisticsInfoVO countDeviceAndGroupByProgramVersion(String programVersion) {
        return programDeviceMapper.countDeviceAndGroupByProgramVersion(programVersion);
    }

    /**
     * 新增单条
     *
     * @param programDevice 数据
     * @return 影响行数
     */
    @Override
    public int insert(ProgramDevice programDevice) {
        return programDeviceMapper.insert(programDevice);
    }

    /**
     * 批量删除
     *
     * @param programVersionList 节目版本号
     * @param deviceCodeList     设备序列号
     */
    @Transactional(propagation=Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    @Override
    public void batchDelete(List<String> programVersionList, List<String> deviceCodeList) {
        programDeviceMapper.batchDelete(programVersionList, deviceCodeList, System.currentTimeMillis());
    }

    /**
     * 查询列表
     *
     * @param programVersion 节目版本号
     * @return List
     */
    @Override
    public List<ProgramDevice> list(String programVersion) {
        return programDeviceMapper.list(programVersion);
    }
}
